package com.wzy.Immutable;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.ImmutableList;

public class immutableTest
{
	public static void removeFirstElement(List<Integer> ints)
	{
		ints.remove(0);
	}

	public static void main(String[] args)
	{
		List<Integer> ints = new ArrayList<>();
		ints.add(0);
		ints.add(1);
		ints.add(2);
		// 使用jdk自带的方法，使ints转为不可变的集合
		// List<Integer> immutableList = Collections.unmodifiableList(ints);

		// 使用guava
		ImmutableList<Integer> immutableList = ImmutableList.copyOf(ints);

		removeFirstElement(immutableList);

		System.out.println(ints);

	}

	/**
	 * copyOf方法
	 * of方法
	 * Builder 方法 (需要一个一个追加)
	 */
	public static void createImmutableCollectionByGuava()
	{
		ImmutableList<Object> createListWithBuild = ImmutableList.builder().add(1).add(2).build();
		ImmutableList<Integer> immutableList = ImmutableList.of(1, 2, 3);
		removeFirstElement(immutableList);
	}


}
